//访问器
//需求的变化导致类的变化

class Visitor;

class Element
{
public:
	virtual void accept(Visitor& visitor) = 0; //第一次动态辨析
	virtual ~Element(){}
};

class ElementA:public Element
{
public:
	void accept(Visitor& visitor) override
	{
		visitor.visitElementA(*this);
	}
};

class ElementB:public Element
{
public:
	void accept(Visitor& visitor) override
	{
		visitor.visitElementB(*this); //第二次动态辨析
	}
};

class Visitor
{
public:
	virtual void visitElementA(Element& element) = 0;
	virtual void visitElementB(Element& element) = 0;
	virtual ~Visitor(){}
};
                                // Element子类的个数是确定的 ，稳定
///////////////////////////////////////////////////////////////
                                                           //扩展
class Visitor1:public Visitor
{
public:
	virtual void visitElementA(Element& element) override
	{

	}
	virtual void visitElementB(Element& element) override
	{

	}
};


class Visitor2:public Visitor
{
public:
	virtual void visitElementA(Element& element) override
	{

	}
	virtual void visitElementB(Element& element) override
	{

	}
};


int main()
{
	Visitor visitor;
	ElementB elementB;
	ElementB.accept(visitor);//两次 dispatch
}
